/*
 * test_db.cpp

 *
 *  Created on: Jan 3, 2014
 *      Author: killerg
 */

#include "share/db_mgr.h"
#include <stdio.h>
#include <unistd.h>
#include "share/clock.h"



my_clock_t g_clock;
db_mgr_t db;
Json::Value value;
int num = 0;

bool test_db() {
    g_clock.init(100);
    if (!db.init("192.168.1.3", "", "", "default")) {
        return false;
    }

    if (db.ok()) {
        value["num"] = num++;
        bool res = db.set("hello", value, [](db_error_t err){
            if (DBE_Success != err)
                --num;
        });
        if (!res) {
            --num;
        }
    }

    while (true) {
        g_clock.begin_update();
        if (db.ok()) {
            value["num"] = num++;
            bool res = db.set("hello", value, [](db_error_t err){
                if (DBE_Success != err)
                    --num;
                else
                    printf("%d\n", num);
            });
            if (!res) {
                --num;
            }
        }
        else {
            printf("err\n");
        }

        db.update();
        g_clock.end_update();
        g_clock.wait_frame();

        if (g_clock.sec_jump) {

        }
    }

    db.destroy();

    return true;
}


